<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>问候语</div>
    <img src="" alt="">
    <script>
        var hi = document.getElementsByTagName('div');
        var img = document.getElementsByTagName('img');
        var now = new Date();
        // console.dir(hi);
        // console.dir(img);
        // console.log(now);
        // console.log(hi[0].innerText);

        if (6 <= now.getHours() && now.getHours() < 12) {
            console.log(now.getHours());
            img[0].src = "images/z.gif";
            hi[0].innerText = '早上好！';
        } else if (12 <= now.getHours() && now.getHours() < 18) {
            console.log(now.getHours());
            img[0].src = "images/x.gif";
            hi[0].innerText = '下午好！';
        } else {
            console.log(now.getHours());
            img[0].src = "images/w.gif";
            hi[0].innerText = '晚上好！';
        }
    </script>
</body>

</html>